Use LINQ to right queries against the objects in your code using the Reflection APIs.
Press F5
The sample shows how to use methods from the System.Reflection namespace to run queries over types from System.Xml.Linq.dll. The by-product is an HTML document outlining the public APIs for the assembly.
The Reflector application generates an HTML document that outlines the public API for a given assembly. The task is achieved in two phases. First, an XML document is emitted in memory. (See method Emit*().) The document captures the relevant aspects of the assembly's metadata. In the second phase, an HTML document is extracted from the XML document. (See method Extract*().) Note that the two phases use the same query constructions to handle similar information in different representations.
XElement EmitAssembly(Assembly assembly)
{
return new XElement("assembly",
new XAttribute("name", assembly.ManifestModule.Name),
from type in assembly.GetTypes()
where GetVisible(type)
group type by GetNamespace(type) into g
orderby g.Key
select EmitNamespace(g.Key, g));
}
XElement EmitAssembly(Assembly assembly)
{
return new XElement("assembly",
new XAttribute("name", assembly.ManifestModule.Name),
from type in assembly.GetTypes()
where GetVisible(type)
group type by GetNamespace(type) into g
orderby g.Key
select EmitNamespace(g.Key, g));
}
Public Function EmitAssembly(ByVal assembly As Assembly) As XElement
Return <assembly name=<%= assembly.ManifestModule.Name %>>
<%= From type In assembly.GetTypes() _
Where GetVisible(type) _
Group type By GetNamespace = GetNamespace(type) Into g = Group _
Order By GetNamespace _
Select EmitNamespace(GetNamespace, g) %>
</assembly>
End Function
Public Function EmitAssembly(ByVal assembly As Assembly) As XElement Return <assembly name=<%= assembly.ManifestModule.Name %>> <%= From type In assembly.GetTypes() _ Where GetVisible(type) _ Group type By GetNamespace = GetNamespace(type) Into g = Group _ Order By GetNamespace _ Select EmitNamespace(GetNamespace, g) %> </assembly> End Function